#import "DDHelper.h"
#import "DDPlatform.h"

NSString *const HTMLGAME = @"H5";
@interface DDHelper()
{
    NSMutableDictionary *_localInfo;
    NSMutableArray *_accountArr;
    NSMutableArray *_a;

}
@end
@implementation DDHelper
static DDHelper*_helper;
static dispatch_once_t JTWHelperToken;
+ (instancetype)help
{
    if (!_helper)
    {
        dispatch_once(&JTWHelperToken,^{
            _helper = [[DDHelper alloc]init];
            [CCNotice addObs:_helper sel:@selector(getIP:) name:CCNoticeNameIP obj:nil];
            [CCNotice addObs:_helper sel:@selector(getMoveTouch:) name:CCNoticeNameMoveTouchClicked obj:nil];
        });
    }
    return  _helper;
}

- (CCMoveTouch *)userBtn
{
    if (!_userBtn)
    {
        _userBtn = [CCMoveTouch touch];
        _userBtn.image = [@"centerLogo" dd_image];
    }
    return _userBtn;
}
- (NSDictionary *)localInfo
{
    if (!_localInfo)
    {
        _localInfo = [NSMutableDictionary dictionary];
        NSString *wifi = [[CCIP IP].SSID hasPrefix:@"非wifi"]?[NSString stringWithFormat:@"%@/%@/%@", [CCDevice version], [CCDevice deviceType], [CCDevice networkType]]:[CCIP IP].SSID;
        [_localInfo setValue:[CCDevice UUID] forKey:@"imei"];
        [_localInfo setValue:[CCIP IP].wanIP?[CCIP IP].wanIP:@"" forKey:@"ip"];
        [_localInfo setValue:wifi forKey:@"network"];
        [_localInfo setValue:self.appID forKey:@"appid"];
        [_localInfo setValue:self.channelID forKey:@"channelaccountid"];
        [_localInfo setValue:@"1"forKey:@"terminal"];
    }
    return _localInfo;
}
- (NSMutableArray *)accountArr
{
    if (!_accountArr)
    {
        _accountArr = [[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"JTWTokenKey"];
    }
    return _accountArr;
}
- (UIColor *)color
{
    if (!_color)
    {
        _color = [UIColor purpleColor];
    }
    return _color;
}
- (NSString *)appID
{
    return [[DDPlatform platform] valueForKey:@"appID"];
}
- (NSString *)channelID
{
    return [[DDPlatform platform] valueForKey:@"channelID"];
}
- (NSString *)serviceHeader
{
    return [[DDPlatform platform] valueForKey:@"serviceHeader"];
}
- (NSString *)key
{
    return [[DDPlatform platform] valueForKey:@"key"];
}
- (NSString *)country
{
    return [CCIP IP].wanCountry;
}
- (NSString *)city
{
    return [CCIP IP].wanCity;
}
- (NSString *)region
{
    return [CCIP IP].wanRegion;
}
- (void)getIP:(NSNotification *)notify
{
    [self.localInfo setValue:[CCIP IP].wanIP?[CCIP IP].wanIP:@"" forKey:@"ip"];
}
- (void)getMoveTouch:(NSNotification *)notify
{
    UIViewController *vc = (UIViewController *)[UIViewController currentVC];
    if (![NSStringFromClass([vc class]) isEqualToString:@"DDPersonViewController"])
    {
        UIViewController *presentingVC = [NSClassFromString(@"DDPersonViewController") new];
        presentingVC.modalTransitionStyle =  UIModalTransitionStyleCoverVertical;
        presentingVC.modalPresentationStyle = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)?UIModalPresentationFormSheet:UIModalPresentationOverCurrentContext;
        presentingVC.view.backgroundColor = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)?[UIColor whiteColor]:[UIColor clearColor];
        [vc presentViewController:presentingVC animated:YES completion:nil];
    }
}
+ (void)dd_insertAccountDict:(NSDictionary *)dict
{
    _helper = [DDHelper help];
    _helper->_account = [dict valueForKey:@"name"];
    NSString *password = [dict valueForKey:@"password"];
    if (_helper->_account && password)
        [_helper.accountArr dd_enumerate:@{_helper->_account:password}];
}
@end
